package psmanager.swing.action;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.Map;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.KeyStroke;

import psmanager.db.DBManager;

public class Actions {
	
	/**
	 * Map that contains all used icons.
	 */
	private static Map<String, Action> allActions;

	/**
	 * Creation of all actions.
	 */
	@SuppressWarnings("serial")
	public static void createActions(final DBManager dbm) {
		
		allActions = new HashMap<String, Action>();

		Action fileExit = new AbstractAction("Exit") {
			public void actionPerformed(ActionEvent event) {
				dbm.cleanUp();
				System.exit(0);
			}
		};
		fileExit.putValue(Action.SHORT_DESCRIPTION, "Exit application.");
		fileExit.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
		fileExit.putValue(Action.ACCELERATOR_KEY, 
			KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
		allActions.put("Exit", fileExit);
		
	}
	
	public static Action getAction(String key) {
		return allActions.get(key);
	}
	
}
